﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Caching;
using System.Web;
using System.Collections;

namespace Tools
{
    /// <summary>
    /// 缓存处理
    /// </summary>
    public static class CacheData
    {
        /// <summary>
        /// 获取当前缓存指定CacheKey的Cache值
        /// </summary>
        /// <param name="CacheKey"></param>
        /// <returns></returns>
        public static object GetCache(string CacheKey)
        {
            return HttpRuntime.Cache.Get(CacheKey);
        }

        /// <summary>
        /// 移除当前缓存指定CacheKey的Cache值
        /// </summary>
        /// <param name="CacheKey"></param>
        /// <returns></returns>
        public static void RemoveCache(string CacheKey)
        {
            HttpRuntime.Cache.Remove(CacheKey);
        }

        /// <summary>
        /// 设置当前缓存指定CacheKey的Cache值
        /// </summary>
        /// <param name="CacheKey">缓存名称</param>
        /// <param name="objObject">缓存值</param>
        public static void InsertCache(string CacheKey, object objObject)
        {
            HttpRuntime.Cache.Insert(CacheKey, objObject);
        }

        /// <summary>
        /// 设置当前缓存指定CacheKey的Cache值
        /// </summary>
        /// <param name="CacheKey">缓存名称</param>
        /// <param name="objObject">缓存值</param>
        /// <param name="time">可调到期时间(分钟)</param>
        public static void InsertCache(string CacheKey, object objObject, double time)
        {
            HttpRuntime.Cache.Insert(CacheKey, objObject, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(time));
        }

        /// <summary>
        /// 设置当前缓存指定CacheKey的Cache值
        /// </summary>
        /// <param name="CacheKey">缓存名称</param>
        /// <param name="objObject">缓存值</param>
        /// <param name="fileName">缓存依赖项</param>
        public static void InsertCache(string CacheKey, object objObject, string fileName)
        {
            HttpRuntime.Cache.Insert(CacheKey, objObject, new CacheDependency(fileName));
        }

        /// <summary>
        /// 设置当前缓存指定CacheKey的Cache值
        /// </summary>
        /// <param name="CacheKey">缓存名称</param>
        /// <param name="objObject">缓存值</param>
        /// <param name="CacheDependency">缓存依赖项</param>
        public static void InsertCache(string CacheKey, object objObject, string[] DependKeys)
        {
            HttpRuntime.Cache.Insert(CacheKey, objObject, new CacheDependency(null, DependKeys));
        }

        /// <summary>
        /// 设置当前缓存指定CacheKey的Cache值
        /// </summary>
        /// <param name="CacheKey">缓存名称</param>
        /// <param name="objObject">缓存值</param>
        /// <param name="CacheDependency">缓存依赖项</param>
        /// <param name="time">可调到期时间(分钟)</param>
        public static void InsertCache(string CacheKey, object objObject, string[] DependKeys, double time)
        {
            HttpRuntime.Cache.Insert(CacheKey, objObject, new CacheDependency(null, DependKeys), Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(time));
        }
    }
}
